document.addEventListener("DOMContentLoaded", () => {
    const form = document.querySelector("#login-form");
    if (!form) return;

    form.addEventListener("submit", (e) => {
        e.preventDefault();

        const username = document.querySelector("#username").value.trim();
        const password = document.querySelector("#password").value.trim();

        if (!username || !password) {
            alert("请输入用户名和密码！");
            return;
        }

        // 模拟登录（可改成调用后端接口）
        if (username === "admin" && password === "123456") {
            localStorage.setItem("user", JSON.stringify({ username }));
            alert("登录成功！");
            window.location.href = "index.html";
        } else {
            alert("用户名或密码错误！");
        }
    });
});